package com.example.tangjiangxu.viewtest;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {
    private MyListView mListView;
    private MyAdapter mAdapter;
    private List<String> contentList = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LinearLayout viewMain = (LinearLayout) findViewById(R.id.activity_main);
        initList();
        mListView = (MyListView) findViewById(R.id.lv);
        mListView.setDeleteListener(new MyListView.OnDeleteListener() {
            @Override
            public void onDelete(int index) {
                contentList.remove(index);
                mAdapter.notifyDataSetChanged();
            }
        });
        mAdapter = new MyAdapter(this, 0, contentList);
        mListView.setAdapter(mAdapter);
        //View viewButton = LayoutInflater.from(this).inflate(R.layout.button, viewMain, true);
        //viewMain.addView(viewButton);
    }

    private void initList() {
        contentList.add("content 1");
        contentList.add("content 2");
        contentList.add("content 3");
        contentList.add("content 4");
        contentList.add("content 5");
        contentList.add("content 6");
        contentList.add("content 7");
        contentList.add("content 8");
        contentList.add("content 9");
        contentList.add("content 10");
        contentList.add("content 11");
        contentList.add("content 12");
        contentList.add("content 13");
        contentList.add("content 14");
        contentList.add("content 15");
        contentList.add("content 16");
        contentList.add("content 17");
    }
}
